import {amap, requests, requestsLongtime} from "@/api/request";

/*//获取Features列表，前端递归调用
export const reqGetFeaturesInfo = (level,parentId)=>requests({
    url:'/features',
    params:{
        level,
        parentId
    },
    method:'get',
    headers:{
        'token':getToken()
    }
})*/

/**
 * 获取Features列表，后端的递归调用
 * @returns {AxiosPromise}
 */
export const reqGetFeatureList = ()=>requestsLongtime({
    url:'/features/getfeaturelist',
    method:'get',
})
/**
 * 获取featureId的Geometry
 * @param featureId
 * @returns {AxiosPromise}
 */
export const reqGetFeatureByFeatureId=(featureId)=>requests({
    url:'/features/getFeature',
    params: {featureId},
    method:'get',
})
/**
 * 适配el_tree动态加载数据
 * @param level
 * @param parentId
 * @returns {*}
 */
export const reqGetFeatureListTree = (level, parentId)=>requestsLongtime({
    url:"/features/getFeatureListTree",
    params:{
        level:level,
        parentId:parentId
    }
})
/**
 * 上传文件转换为Features,Feature
 * @param data
 * @returns {*}
 */
export const reqUpdateFeaturesByFile = (data)=>requestsLongtime({
    url:'/features/upload',
    data:data,
    method:'post'
})
/*
* params: position=[114.35,32.23]
* */
// 通过高德地图api转化，
export const reqConvert = (position)=> {
    const locationsParam = position.reduce((total,cur)=>{
        return total+`${cur[0]},${cur[1]}|`
    },'')
    return amap({
        url: '/assistant/coordinate/convert',
        params: {locations: locationsParam}
    })
}

/**
 * 根据json数据，返回features数据
 * @param data
 * @returns {*}
 */
export const reqGetFeaturesInfoByFile = (data)=>requestsLongtime({
    url:'/features/getFeaturesInfoByFile',
    data:data,
    method:'post'
})
/**
 * 删除Feature数据,提供level,id
 * @param data
 * @returns {*}
 */
export const reqDeleteFeatures = (data)=>requestsLongtime({
    url:'/features/deleteByLevelAndId',
    params:data,
    method:'delete',
})
/**
 * 根据json对象更新Features,Feature数据
 * @param data
 * @returns {*}
 */
export const reqUpdateFeatureByJson =(data)=>requests({
    url:'/features/updateFeatureByJson',
    data,
    method:"post",
})
/**
 * 更新redis中的FeatureList列表
 * @returns {*}
 */
export const reqUpdateFeatureList =()=>requests({
    url:'/features/updateFeaturesList',
})